home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 1.iso
/
toolbox
/
src
/
tutorials
/
custEducation
/
opengl2
/
lib
/
rgbWriteImageFile.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-11-11
|
3KB
|
96 lines
/*
* Copyright 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* rgbWriteImageFile.c
* Modified version of Paul Haeberli's writeimg -
* abgr ordering switched to rgba for OpenGL and prototypes added
* - David Marsland - 1993.
*
* This function takes an array of the form read by glReadPixels and
* puts it in a file in the .rgb format.
*
* Write out an RGB image file. This example uses three functions
* from the image library:
*
* iopen, putrow, and iclose.
*
* The function iopen is called to describe the xsize and ysize of the
* RGB image to be written out.
*
* The function putrow writes a row of image data to the image file. It is
* called with an array of shorts with values in the range [0..255].
*
* The function iclose is called to close the image file.
*
* This function puts an array of the form read by lrectread and
* puts it in a file in the .rgb format.
*
* Paul Haeberli - 1987
*
*/
#include <unistd.h>
#include <GL/gl.h>
#include "rgbImageFile.h"
#include <gl/image.h>
unsigned short rbuf[4096];
unsigned short gbuf[4096];
unsigned short bbuf[4096];
void
rgbWriteImageFile( char *name, GLint xsize, GLint ysize, GLuint *parray)
{
int x,y;
unsigned int cur_col;
IMAGE *image;
/* This program and librgbImageFile both rely on an unsigned
* int being 4 unsigned contiguous bytes. The following test
* checks to see if this is the case.
*/
if ( sizeof( unsigned int ) != 4 )
{
fprintf (stderr, "Warning: sizeof( unsigned int ) != 4,\
this program and librgbImageFile must be modified\n"
);
exit (1);
}
image = iopen(name,"w",RLE(1),3,xsize,ysize,3);
for(y=0; y<ysize; y++) {
/*
fill rbuf, gbuf, and bbuf with pixel values
*/
for (x=0;x<xsize;x++)
{
cur_col = parray[x];
bbuf[x] = (cur_col >> 8)&0xff;
gbuf[x] = (cur_col >> 16)&0xff;
rbuf[x] = (cur_col >> 24)&0xff;
}
putrow(image,rbuf,y,0); /* red row */
putrow(image,gbuf,y,1); /* green row */
putrow(image,bbuf,y,2); /* blue row */
parray += xsize;
}
iclose(image);
}